<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // todo:画出原型链图
    // 0.继承SuperType 
    function SuperType() {
        this.colors = ["red", "blue", "green"];
    }

    // fixme:难以理解
    function SubType() {
        SuperType.call(this);
    }

    let instance1 = new SubType();
    instance1.colors.push("black");
    console.log(instance1, SubType.prototype, SuperType.prototype)
    console.log(instance1.colors); // "red,blue,green,black"
    let instance2 = new SubType();
    console.log(instance2.colors); // "red,blue,green"

    /*
        1.传递参数
     */
    function SuperType1(name) {
        this.name = name;
    }

    function SubType1() {
        // 继承 SuperType 并传参
        SuperType1.call(this, "Nicholas");
        // 实例属性
        this.age = 29;
    }

    let instance = new SubType1();
    console.log(instance.name); // "Nicholas"; console.log(instance.age); // 29
    
    /*
        2.缺点
            - 必须在构造函数中定义方法,因此函数不能重用
            -  子类也不能访问父类原型中定义的方法 
     */

</script>
</body>
</html>